package com.android.wlw_local;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;

import com.farsunset.cim.sdk.android.CIMPushManager;
import com.farsunset.cim.sdk.android.model.SentBody;

/**
 * Created by zhuqin on 2018/1/3.
 */

public class PushActivity extends Activity{
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_push);

        CIMPushManager.connect(this,"120.78.51.39",13131);


        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(CIMPushManager.isConnected(PushActivity.this)){
                    CIMPushManager.bindAccount(PushActivity.this,"zhuqin1");
                }
            }
        });

        findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(CIMPushManager.isConnected(PushActivity.this)){
                    SentBody sentBody = new SentBody();
                    sentBody.setKey("client_bind");
                    sentBody.put("location","2");
                    sentBody.put("account","zhuqinAPP");
                    CIMPushManager.sendRequest(PushActivity.this,sentBody);
                }
            }
        });

        findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(CIMPushManager.isConnected(PushActivity.this)){
                    send("zhuqin",""+111);
                }
            }
        });



    }

    private void send(String account ,String deviceId ){
        SentBody sent = new SentBody();
        sent.setKey("client_bind");
        sent.put("account", account);
        sent.put("deviceId", deviceId);
        sent.put("channel", "android");
        sent.put("device", Build.MODEL);
        sent.put("version", "3.1");
        sent.put("osVersion", Build.VERSION.RELEASE);
        sent.put("packageName", "com.android.wlw_local");
        Log.i("zhuqin",new String(sent.getByteArray()));
    }
}
